#ifndef __XKK_MUTEXLOCK_H__
#define __XKK_MUTEXLOCK_H__

#include "Noncopyable.hpp"
#include <pthread.h>

namespace xkk
{

class MutexLock
    :Noncopyable
{
public:
    MutexLock();
    ~MutexLock();

    void lock();
    void unlock();

    pthread_mutex_t * getMutexLockPtr(){ return &_mutex; }

private:
    pthread_mutex_t _mutex;
    bool _isLocking;
};

class MutexLockGuard
{
public:
    MutexLockGuard(MutexLock &mutex)
        :_mutex(mutex)
    {
        _mutex.lock();
    }
    ~MutexLockGuard()
    {
        _mutex.unlock();
    }
private:
    MutexLock &_mutex;
};

}//end of namespace xkk
#endif

